package expressions.slogo;

import java.util.List;
import parsing.Token;
import model.Turtle;

/**
 * Moves the turtle to a new coordinate (x, y).
 */
@Token(regex = "setxy")
public class SetXY extends TurtleCommand
{

    public SetXY()
    {
        super(2);
    }

    @Override
    protected Double combineResults(List<Double> results, ITurtleContext context)
    {
        Turtle t = context.getTurtle();
        double oldx, oldy, newx, newy;
        oldx = t.getX();
        oldy = t.getY();
        newx = results.get(0);
        newy = results.get(1);

        /*
         * Move the turtle to the new coordinate.
         */
        t.move(newx, newy);

        /*
         * Return how many pixels the turtle moved.
         */
        return Math.sqrt(Math.pow(newx - oldx, 2) + Math.pow(newy - oldy, 2));
    }

}
